package com.is.exportword;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.is.util.ParamUtil;

public class ShowPic extends HttpServlet {


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("image/jpeg");      //设置返回内容格式
		String basePath =this.getServletConfig().getServletContext().getRealPath("/");
		String fileName = ParamUtil.getString(request, "picUrl",null);
		String absolutePath = basePath+fileName.replace("/InterStu/", "").replace("/", "\\");
//		absolutePath = "D:\\1.jpg";
		System.out.println(absolutePath);
		if(fileName!=null){
		    File file = new File(absolutePath);       //括号里参数为文件图片路径
		    if(file.exists()){    
		     InputStream in = new FileInputStream(absolutePath);   //用该文件创建一个输入流
		     OutputStream os = response.getOutputStream();  //创建输出流
		     byte[] b = new byte[1024];  
		     while( in.read(b)!= -1){  
		      os.write(b);     
		     }
		     in.close(); 
		     os.flush();
		     os.close();
		    }
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
this.doGet(request, response);
	}

	public void init() throws ServletException {
		// Put your code here
	}

}
